package edu.hawaii.duedates.book;

import static org.junit.Assert.assertTrue;
import java.util.Calendar;
import java.util.Locale;
import org.junit.Test;

/**
 * This will test the DueDateComparator, LibraryComparator, and TitleComparator classes.
 * 
 * @author Ronn Reeves 
 */
public class TestComparators {
  Calendar today = Calendar.getInstance(Locale.US);
  Calendar tomorrow = Calendar.getInstance(Locale.US);
  Book book1 = new Book("Book1", today, "Library A");

  /**
   * Test DueDateComparator.
   */
  @Test
  public void testDueDateComparator() {
    DueDateComparator ddc = new DueDateComparator();

    tomorrow.add(Calendar.DAY_OF_MONTH, 1);
    Book book2 = new Book("Book2", tomorrow, "Library B");
    assertTrue("DueDateComparator failed.", ddc.compare(book1, book2) < 0);
    assertTrue("DueDateComparator failed.", ddc.compare(book2, book1) > 0);
  }
  
  /**
   * Test LibraryComparator.
   */
  @Test
  public void testLibraryComparator() {
    LibraryComparator lc = new LibraryComparator();
    Book book2 = new Book("Book2", tomorrow, "Library B");
    assertTrue("LibraryComparator failed.", lc.compare(book1, book2) < 0);
    assertTrue("LibraryComparator failed.", lc.compare(book2, book1) > 0);
  }
  
  /**
   * Test TitleComparator.
   */
  @Test
  public void testTitleComparator() {
    TitleComparator tc = new TitleComparator();
    Book book2 = new Book("Book2", tomorrow, "Library B");
    assertTrue("TitleComparator failed.", tc.compare(book1, book2) < 0);
    assertTrue("TitleComparator failed.", tc.compare(book2, book1) > 0);
  }
}